<?php

namespace app\common\lib;

use think\facade\Db;

class Push
{
    public function __construct($web){
        if(empty($web)){
            return null;
        }
        switch ($web['cms_type']) {
            case 'eyoucms':
                $this->cms = new \app\common\lib\Eyoucms($web);
            break;
            case 'destoon':
                
            break;
            case 'dedecms':
                
            break;
        }
    }

    public function project($param)
    {
        $arcid = $this->cms->insertProject($param);
        if(empty($arcid)){
            return null;
        }
        if(empty($param['company'])){
            return $arcid;
        }
        $dataCom = $this->cms->getCompany($param['company']);
        if(!empty($dataCom)){
            $this->cms->updateProject($arcid,['company_address'=>$dataCom['address']]);
            return $arcid;
        }
        $dataCom = Db::name('data_company')->where('title',$param['company'])->find();
        if(!empty($dataCom)){
            $this->cms->updateProject($arcid,['company_address'=>$dataCom['address']]);
            $this->cms->insertCompany($dataCom);
        }
        return $arcid;
    }

    public function article($param){
        $arcid = $this->cms->insertArticle($param);
        if(empty($arcid)){
            return null;
        }
        return $arcid;
    }

    
}